﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CentrisScraper.Lib.Emails
{
    /// <summary>
    /// Email that can be sent via an EmailSender
    /// An email can contains one or more attachment
    /// </summary>
    public class Email
    {
        private static SmtpEmailSender emailSender = new SmtpEmailSender();
        private string from;
        private string to;
        private string cc;
        private string bcc;
        private string subject;
        private string body;
        private IList<string> attachments;

        /// <summary>
        /// From
        /// </summary>
        public string From 
        { 
            get { return from; } 
            set { from = value; } 
        }

        /// <summary>
        /// To
        /// </summary>
        public string To 
        { 
            get { return to; } 
            set { to = value; } 
        }

        /// <summary>
        /// Cc
        /// </summary>
        public string Cc 
        { 
            get { return cc; } 
            set { cc = value; } 
        }

        /// <summary>
        /// Bcc
        /// </summary>
        public string Bcc 
        { 
            get { return bcc; } 
            set { bcc = value; } 
        }

        /// <summary>
        /// Subject
        /// </summary>
        public string Subject 
        { 
            get { return subject; } 
            set { subject = value; } 
        }

        /// <summary>
        /// Body
        /// </summary>
        public string Body 
        { 
            get { return body; } 
            set { body = value; }
        }

        /// <summary>
        /// Email's attachments
        /// </summary>
        public IList<string> Attachments
        {
            get 
            { 
                if (attachments == null)
                    attachments = new List<string>();
                return attachments; 
            }
            set { attachments = value; }
        }

        /// <summary>
        /// Add an attachment to the email
        /// </summary>
        /// <param name="filePath"></param>
        public void AddAttachment(string filePath)
        {
            Attachments.Add(filePath);
        }

        /// <summary>
        /// Send the email
        /// </summary>
        public void Send()
        {
            if (!string.IsNullOrWhiteSpace(to))
            {
                emailSender.Send(this);
            }
        }

    }
}
